<template>
  <div class="app-container">
    <!-- 查询条件开始 -->
    <el-form
      ref="queryForm"
      :model="queryParams"
      :inline="true"
      label-width="98px"
    >
      <!-- <el-form-item label="医生ID" prop="valueId">
        <el-input
          v-model="queryParams.valueId"
          placeholder="请输入医生ID"
          clearable
          size="small"
          style="width: 180px"
        />
      </el-form-item> -->
      <el-form-item label="医生姓名" prop="name">
        <el-input
          v-model="queryParams.name"
          placeholder="请输入医生姓名"
          clearable
          size="small"
          style="width: 180px"
        />
      </el-form-item>

      <el-form-item label="创建时间">
        <el-date-picker
          v-model="queryParams.dateRange"
          size="small"
          style="width: 240px"
          value-format="yyyy-MM-dd"
          type="daterange"
          range-separator="-"
          start-placeholde="开始日期"
          end-placeholde="结束日期"
        />
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button
          type="primary"
          icon="el-icon-refresh"
          size="mini"
          @click="resetQuery"
          >重置</el-button
        >
        <el-button
          type="danger"
          icon="el-icon-delete"
          size="mini"
          :disabled="multiple"
          @click="handleDelete"
          >删除</el-button
        >
      </el-form-item>
    </el-form>
    <!-- 查询条件结束 -->

    <!-- 数据表格开始 -->
    <el-table
      v-loading="loading"
      border
      :data="commentTableList"
      @selection-change="handleSelectionChnage"
    >
      <el-table-column type="selection" width="55" align="center" />
      <el-table-column label="id" align="center" prop="id" />
      <!-- <el-table-column
        label="医生ID"
        align="center"
        width="120"
        prop="valueId"
      /> -->
      <el-table-column label="医生名称" align="center" prop="name">
      </el-table-column>
      <el-table-column label="评论内容" align="center" prop="content"  />
      <el-table-column label="评分" align="center" >
        <template slot-scope="scope">
          <el-rate
            v-model="scope.row.star"
            :colors="colors"
            show-text
            disabled
          ></el-rate>
        </template>
      </el-table-column>

      <el-table-column label="类型" prop="commnetType" align="center">{{
        commnetType
      }}</el-table-column>
      <el-table-column label="创建时间" align="center" prop="addTime" />
      <el-table-column label="操作" align="center">
        <template slot-scope="scope">
          <el-button
            type="text"
            icon="el-icon-delete"
            size="mini"
            @click="handleDelete(scope.row)"
            >删除</el-button
          >
        </template>
      </el-table-column>
    </el-table>
    <!-- 数据表格结束 -->
    <!-- 分页控件开始 -->
    <el-pagination
      v-show="total > 0"
      :current-page="queryParams.pageNum"
      :page-sizes="[5, 10, 15, 20]"
      :page-size="queryParams.pageSize"
      layout="total, sizes, prev, pager, next, jumper"
      :total="total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
    <!-- 分页控件结束 -->
  </div>
</template>
<script>
// 引入api
import {
  queryAllNew,
  deleteNewByIds,
  getdocNameById,
} from "@/apis/statistics/comment";

export default {
  // 定义页面数据
  data() {
    return {
      // 是否启用遮罩层
      loading: false,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 分页数据总条数
      total: 0,
      // 字典表格数据
      commentTableList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 状态数据字典
      // statusOptions: [],
      // 类型数据字典
      typeOptions: [],
      // 时间条件
      dateRange: [],
      // 查询参数

      colors: ["#99A9BF", "#F7BA2A", "#FF9900"],

      queryParams: {
        pageNum: 1,
        pageSize: 5,
        valueId: undefined,
        dateRange: undefined,
        name:undefined,
      },
      docName: undefined,
      commnetType: undefined,
    };
  },
  // 勾子
  created() {
    // 使用全局的根据字典类型查询字典数据的方法查询字典数据
    // getDictDataAPI("sys_normal_disable").then((res) => {
    //   this.statusOptions = res.data;
    // });
    // 查询表格数据
    this.getProducterList();
  },
  // 方法
  methods: {
    // 查询表格数据
    getProducterList() {
      this.loading = true; // 打开遮罩
      queryAllNew(this.queryParams).then((res) => {
        console.log(res.data)
        let array = res.data;
        array.forEach((element) => {
          this.queryDocNameById(element.valueId)
          if (element.type == 1) {
            this.commnetType = "对医生评论";
            
          }
          if (element.type == 2) {
            this.commnetType = "普通评论";
          }
          if (element.type == 3) {
            this.commnetType = "专题评论";
          }
        });
        
        this.commentTableList = res.data;

        console.log(res.data.length)
        this.total = res.data.length;
        this.loading = false; // 关闭遮罩
      });
    },
    queryDocNameById(row) {
      getdocNameById(row).then((res) => {
        this.docName=res.data.userName;
      });
    },

    // 条件查询
    handleQuery() {
      this.getProducterList();
    },
    // 重置查询条件
    resetQuery() {
      this.resetForm("queryForm");
      this.queryParams.dateRange = null;
      this.getProducterList();
    },

    // 数据表格的多选择框选择时触发
    handleSelectionChnage(selection) {
      this.ids = selection.map((item) => item.id);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
    },
    // 分页pageSize变化时触发
    handleSizeChange(val) {
      this.queryParams.pageSize = val;
      // 重新查询
      this.getProducterList();
    },
    // 点击上一页  下一页，跳转到哪一页面时触发
    handleCurrentChange(val) {
      this.queryParams.pageNum = val;
      // 重新查询
      this.getProducterList();
    },

    // 执行删除
    handleDelete(row) {
      // console.log(row)
      const valueIds = row.id || this.ids;
      const tx = this;
      tx.$confirm("此操作将永久删除该生产厂家数据, 是否继续?", "提示", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          tx.loading = true;
          deleteNewByIds(valueIds)
            .then((res) => {
              tx.loading = false;
              tx.msgSuccess("删除成功");
              tx.getProducterList(); // 全查询
            })
            .catch(() => {
              tx.msgError("删除失败");
              tx.loading = false;
            });
        })
        .catch(() => {
          tx.msgError("删除已取消");
          tx.loading = false;
        });
    },
    // 取消
    cancel() {
      this.open = false;
      this.title = "";
    },
    // 重置表单
    reset() {
      this.resetForm("form");
      this.form = {
        producterId: undefined,
        producterName: undefined,
        producterCode: undefined,
        producterTel: undefined,
        keywords: undefined,
        status: "0",
      };
    },
  },
};
</script>
